import pygame


class Traps:
    def __init__(self, x, y, trap_type, if_visible):
        self.type = trap_type  # type 0: damage, type 1: freeze
        self.if_v = if_visible
        self.coord_x = x
        self.coord_y = y
        self.triggered = False
        if self.type == 0:
            self.image_armed = pygame.image.load(r"image/armed_explode_trap.png")
            self.image_triggered = pygame.image.load(r"image/broken_explode_trap.png")
        elif self.type == 1:
            self.image_armed = pygame.image.load(r"image/armed_freeze_trap.png")
            self.image_triggered = pygame.image.load(r"image/broken_freeze_trap.png")
        if not self.if_v:
            self.image_armed = pygame.image.load(r"image/blank_trap.png")
        self.image = self.image_armed

    # trigger current trap
    def trigger(self):
        if ~self.triggered:
            self.triggered = True
            if self.type == 0:
                sound = pygame.mixer.Sound("sound/sound_effect/explode_trap.mp3")
            else:
                sound = pygame.mixer.Sound("sound/sound_effect/freeze.wav")
            sound.set_volume(1)
            sound.play()
            self.image = self.image_triggered

    # judge if the trap is still not triggered
    def functioning(self):
        if self.triggered:
            return False
        else:
            return True
